
    /********************************************************/
    /*                                                      */
    /*                                                      */
    /*         Copyright (C), 1993  SEIKO EPSON Corp.       */
    /*         ALL RIGHTS RESERVED                          */
    /*                                                      */
    /*                                                      */
    /*  file name : gets.c                                  */
    /*                                                      */
    /*  Revision history                                    */
    /*      93/12/17    first release       S.Akaiwa        */
    /*      97/3/17	modified	    T.Katahira	    */
    /*			change function declaration	    */
    /*					to the ANSI style   */
    /*                                                      */
    /********************************************************/

#ifdef  UNIX
#include    "stdio.h"
#else
#include    <stdio.h>
#endif

char    *
gets(char * cBufP)

    /********************************************************/
    /*                                                      */
    /*  The gets function reads a line from the standard    */
    /*  input stream.                                       */
    /*  '\n' character is discarded, and a '\0' character   */
    /*  is written after the last character.                */
    /*  NULL pointer cannot be specified for storage        */
    /*  pointer.                                            */
    /*  If number of reads character over the INT_MAX,      */
    /*  behavior is undefined.                              */
    /*                                                      */
    /*      RETURN  Except NULL ... Pointer to string       */
    /*              NULL        ... Error                   */
    /*                                                      */
    /*  <ANSI>                                              */
    /*      The gets function reads a line from the         */
    /*      standard input stream.                          */
    /*                                                      */
    /*      RETURN  Except NULL ... Pointer to string       */
    /*              NULL        ... Error                   */
    /*                                                      */
    /********************************************************/

    /* char    *cBufP  ;     pointer to data storage buffer */
    {

     int    iOfst;
     int    iDat;

     iOfst = 0;                             /* clear offset */


                               /* read character until '\n' */
     while((iDat = getc(stdin)) != '\n'){
        if(iDat == EOF){          
           break;                              /* found EOF */
        }
        cBufP[iOfst] = (char)iDat;  /* store data to buffer */
        iOfst++;
     }
     
     cBufP[iOfst] = '\0';                 /* set terminator */
     if((iDat == EOF) && (iOfst == 0)){
        return (char *)NULL;         /* data does not exist */
     }     
     return (char *)cBufP;        /* return storage pointer */
    }


